const app = getApp()
Page({
  
  onLoad() {
    
  },
  data: {
    picbox: '',
    information: '',
    scale: 14,
    longitude: 117.30794,
    latitude: 31.79322,
    markers: [{
      iconPath: "https://static.jxqyfw.com/upload/20220708/672cf30ac2ff4b09bf4c1e717e50757d.png",
      id: 1,
      latitude: 31.99115,
      longitude: 116.971642,
      width: 50,
      height: 50,
      label:{
        content: "Hello Label",
        color: "#000000",
        fontSize: 12,
        borderRadius: "3",
        bgColor: "#ffffff",
        padding: 5,
      }
      
    },
      {
        iconPath: "https://static.jxqyfw.com/upload/20220526/192913a6e9e04f75ba3ec015599a175e.png",
        id: 3,
        latitude: 31.79322,
        longitude: 117.30794,
        width: 50,
        height: 50,
        label: {
          content: "Hello Label2222",
          color: "#000000",

          fontSize: 12,

          borderRadius: "3",

          bgColor: "#ffffff",

          padding: 5,
        }
      }],
    includePoints: [{
      latitude: 31.99115,
      longitude: 116.971642,
    },{
      latitude: 31.79322,
      longitude: 117.30794,
    }],
    
    controls: [{
      id: 5,
      iconPath: 'https://static.jxqyfw.com/upload/20220524/90e3f1db9d7745db8a5f1f8b673e84ae.jpg',
      position: {
        left: 0,
        top: 300 - 50,
        width: 50,
        height: 50
      },
      clickable: true
    }],
    panels: [{
      id: 6,
      // 布局参考 map 高级定制渲染
      layout: {
        params: {
          title: "999999999",
          bgColor: "#DC143C"
        },
        src: "http://oss.jxqyfw.com/img/four_02.png"
      },
      position: {
        left: 0,
        top: 0,
        width: 200,
        height: 84
      },
    }],
  },
  onReady(e) {
    // 使用 my.createMapContext 获取 map 上下文
    //22 this.mapCtx = my.createMapContext('map')
  },
  // getCenterLocation() {
  //   this.mapCtx.getCenterLocation(function (res) {
  //     console.log(res.longitude)
  //     console.log(res.latitude)
  //   })
  // },
  // moveToLocation() {
  //   this.mapCtx.moveToLocation()
  // },
  // markertap(e) {
  //   console.log('marker tap', e);

  // },
  // ssss(e) {
  //   my.alert({
  //     title: '1111',
  //     content: e.latitude,
  //     buttonText: '',
  //     success: () => {
  //       my.openLocation({
  //         longitude: e.longitude,
  //         latitude: e.latitude,
  //         name: '黄龙万科中心',
  //         address: '学院路77号',
  //       });
  //     },
  //     fail: () => {
        
  //     },
  //     complete: () => {
        
  //     }
  //   });
  //   console.log('marker tapsss', e);


  // },
  // controltap(e) {
    
  //   console.log('control tap', e);
  // },
  // tap() {
  //   console.log('tap:');
  // },
  // onPanelTap(e) {
  //   console.log('paneltap:', e);
  // },
  // changeScale() {
  //   this.setData({
  //     scale: 8,
  //   });
  // },
  // //支持地图不接受手势事件, isGestureEnable为1 表示支持，为0表示不支持
  // gestureEnable() {
  //   this.mapCtx.gestureEnable({ isGestureEnable: 1 });
  // },

  // //地图是否显示比例尺, isShowsScale 为1表示显示，为0表示不显示
  // showsScale() {
  //   this.mapCtx.showsScale({ isShowsScale: 1 });
  // },
  // //地图是否显示指南针, isShowsCompass 为1表示显示，为0表示不显示
  // showsCompass() {
  //   this.mapCtx.showsCompass({ isShowsCompass: 1 });
  // },
 
  onSubmit(e) {
  var  that =  this;
    if (e.detail.value.textarea == '') {
      my.showToast({
        type: 'fail',
        content: '请描述您的问题!',
        duration: 3000,
        success: () => {

        },
      });
      return
    }
    if (that.data.picbox == '') {
      my.showToast({
        type: 'fail',
        content: '请上传图片!',
        duration: 3000,
        success: () => {

        },
      });
      return
    }
  
   
   
    if (e.detail.value.phonenum == '') {
      my.showToast({
        type: 'fail',
        content: '请输入手机号码!',
        duration: 3000,
        success: () => {

        },
      });
      return
    }
    const regex = /^1[3456789]\d{9}$/;//使用此正则即可
    if (!regex.test(e.detail.value.phonenum)){
      my.showToast({
        type: 'fail',
        content: '请输入正确的手机号码!',
        duration: 3000,
        success: () => {

        },
      });
       return
    }
    if (e.detail.value.ordernum == '') {
      my.showToast({
        type: 'fail',
        content: '请输入订单号!',
        duration: 3000,
        success: () => {

        },
      });
      return
    }
  console.log("@@@",e)
    let infors = {};
    infors.uid = my.getStorageSync({ key: 'user' }).data.id;
    infors.imgs = that.data.picbox;
    infors.orderCode = e.detail.value.ordernum;
    infors.mobile = e.detail.value.phonenum;
    infors.common = e.detail.value.textarea;
    app.other.complaint(infors)
      .then(res => {
        if(res.code == '0'){
           my.alert({
      content: '提交成功',
    });
        setTimeout(() => {
          my.switchTab({
            url: '/pages/main/my/my'
          });
            // my.reLaunch({ url: "/pages/order/renzheng/renzheng?id=" + that.data.orderId });
          }, 500)
        }
        // if (res.code == '0') {
        //   // that.resetOrder()
        //   setTimeout(() => {
        //     my.reLaunch({ url: "/pages/order/renzheng/renzheng?id=" + that.data.orderId });
        //   }, 500)
        // }
        console.log("返回消息", res)
      })
    // my.alert({
    //   content: `数据：${JSON.stringify(e.detail.value)}`,
    // });

  },
  
  onUpload(e) {
    
    const name = e.target.dataset.image;
    //console.log(e);

    my.chooseImage({
      sourceType: ['camera', 'album'],
      count: 1,
      success: (res) => {
        console.log("1111",res)
        const path = res.apFilePaths[0]
        app.other.uploadFile(path)
          .then((res) => {
          console.log("==============",res)
            if (JSON.parse(res.data).code == 0) {
              let str = JSON.parse(res.data).data.fileUrl
              const r = str.split('').reverse().join('');
              const p = r.search(/\./)
              str = r.substring(0, p).split('').reverse().join('');
              //console.log(str)
              if (['jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'].includes(str)) {
                my.showToast({
                  content: '上传成功',
                })
                this.setData({
                  picbox: JSON.parse(res.data).data.fileUrl
                })
              } else if (['UNKNOWN', 'unknown'].includes(str)) {
                my.showToast({
                  content: '图片格式错误，请重新上传',
                })
              } else {
                my.showToast({
                  content: '图片无法识别，请重新上传',
                })
              }
              //console.log(['jpg', 'jpeg', 'png'].includes(str))
            } else {
              my.showToast({
                content: '图片错误，请重新上传', // 文字内容
              });
            }
          })
      },
      fail: () => {
        my.showToast({
          content: '选择错误,请重新选择', // 文字内容
        });
      }
    })
  }
});
